package com.tbit.uqbike.service.business.impl;

import com.github.pagehelper.PageHelper;
import com.tbit.uqbike.object.pojo.BatteryChargeModel;
import com.tbit.uqbike.service.business.BatteryChargeModelService;
import com.tbit.uqbike.webmanager.dao.data.BatteryChargeModelDao;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 电池型号表(BatteryChargeModel)表服务实现类
 *
 * @author jing
 * @since 2020-12-04 09:38:13
 */
@Service("batteryChargeModelService")
public class BatteryChargeModelServiceImpl implements BatteryChargeModelService {
    @Resource
    private BatteryChargeModelDao batteryChargeModelDao;

    /**
     * 通过ID查询单条数据
     *
     * @param batteryModelId 主键
     * @return 实例对象
     */
    @Override
    public BatteryChargeModel queryById(Integer batteryModelId) {
        return this.batteryChargeModelDao.queryById(batteryModelId);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<BatteryChargeModel> queryAllByLimit(int offset, int limit) {
        return this.batteryChargeModelDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param batteryChargeModel 实例对象
     * @return 实例对象
     */
    @Override
    public BatteryChargeModel insert(BatteryChargeModel batteryChargeModel) {
        this.batteryChargeModelDao.insert(batteryChargeModel);
        return batteryChargeModel;
    }

    /**
     * 修改数据
     *
     * @param batteryChargeModel 实例对象
     * @return 实例对象
     */
    @Override
    public BatteryChargeModel update(BatteryChargeModel batteryChargeModel) {
        this.batteryChargeModelDao.update(batteryChargeModel);
        return this.queryById(batteryChargeModel.getBatteryModelId());
    }

    /**
     * 通过主键删除数据
     *
     * @param batteryModelId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer batteryModelId) {
        return this.batteryChargeModelDao.deleteById(batteryModelId) > 0;
    }

    @Override
    public List<BatteryChargeModel> queryPage(BatteryChargeModel batteryChargeModel) {
        PageHelper.startPage(batteryChargeModel.getPage().getPageNO(), batteryChargeModel.getPage().getRowCount());
        return batteryChargeModelDao.queryAll(batteryChargeModel);
    }
}